﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using ProductIntory.Domains;
using ProductIntory.ErrorCodes;
using ProductIntory.Infrastructures.Interface;
using ProductIntory.Read.Apis.Application.Command.ProductInspectionCommands;

namespace ProductIntory.Read.Apis.Application.CommandHandler.ProductInspectionCommandHandlers
{
    public class DeletProductInspectionCommandHandlers : IRequestHandler<DeletProductInspectionCommands, ApiResult<int>>
    {
        IBaseRepository<ProductInspection> ProductInspection;

        public DeletProductInspectionCommandHandlers(IBaseRepository<ProductInspection> ProductInspection)
        {
            this.ProductInspection = ProductInspection;
        }

        public async Task<ApiResult<int>> Handle(DeletProductInspectionCommands request, CancellationToken cancellationToken)
        {
            var list =await ProductInspection.GetAll().Where(c=>c.ProductsInspection_Id == request.id&&c.Isdel==false).FirstOrDefaultAsync();
            if (list != null)
            {
                list.Isdel = true;
                await ProductInspection.Update(list);
            }
            else 
            {

            }

                return new ApiResult<int>
                {
                    Code = ApiEnum.success,
                    Message = "删除成功",
                    Data = 1
                };

        }
    }
}
